.class public Lm/framework/utils/HEX;
.super Ljava/lang/Object;
.source "HEX.java"


# static fields
.field private static final DIGITS:[C


# direct methods
.method static constructor <clinit>()V
    .registers 1

    .prologue
    .line 4
    const/16 v0, 0x10

    new-array v0, v0, [C

    fill-array-data v0, :array_a

    sput-object v0, Lm/framework/utils/HEX;->DIGITS:[C

    return-void

    :array_a
    .array-data 2
        0x30s
        0x31s
        0x32s
        0x33s
        0x34s
        0x35s
        0x36s
        0x37s
        0x38s
        0x39s
        0x61s
        0x62s
        0x63s
        0x64s
        0x65s
        0x66s
    .end array-data
.end method

.method public constructor <init>()V
    .registers 1

    .prologue
    .line 3
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    return-void
.end method

.method public static decodeHex([C)[B
    .registers 8
    .param p0, "data"    # [C

    .prologue
    .line 43
    array-length v3, p0

    .line 45
    .local v3, "len":I
    and-int/lit8 v5, v3, 0x1

    if-eqz v5, :cond_d

    .line 46
    new-instance v5, Ljava/lang/RuntimeException;

    const-string v6, "Odd number of characters."

    invoke-direct {v5, v6}, Ljava/lang/RuntimeException;-><init>(Ljava/lang/String;)V

    throw v5

    .line 49
    :cond_d
    shr-int/lit8 v5, v3, 0x1

    new-array v4, v5, [B

    .line 51
    .local v4, "out":[B
    const/4 v1, 0x0

    .line 52
    .local v1, "i":I
    const/4 v2, 0x0

    .local v2, "j":I
    :goto_13
    if-lt v2, v3, :cond_16

    .line 60
    return-object v4

    .line 53
    :cond_16
    aget-char v5, p0, v2

    invoke-static {v5, v2}, Lm/framework/utils/HEX;->toDigit(CI)I

    move-result v5

    shl-int/lit8 v0, v5, 0x4

    .line 54
    .local v0, "f":I
    add-int/lit8 v2, v2, 0x1

    .line 55
    aget-char v5, p0, v2

    invoke-static {v5, v2}, Lm/framework/utils/HEX;->toDigit(CI)I

    move-result v5

    or-int/2addr v0, v5

    .line 56
    add-int/lit8 v2, v2, 0x1

    .line 57
    and-int/lit16 v5, v0, 0xff

    int-to-byte v5, v5

    aput-byte v5, v4, v1

    .line 52
    add-int/lit8 v1, v1, 0x1

    goto :goto_13
.end method

.method public static decodeHexString(Ljava/lang/String;)[B
    .registers 2
    .param p0, "hexData"    # Ljava/lang/String;

    .prologue
    .line 39
    invoke-virtual {p0}, Ljava/lang/String;->toCharArray()[C

    move-result-object v0

    invoke-static {v0}, Lm/framework/utils/HEX;->decodeHex([C)[B

    move-result-object v0

    return-object v0
.end method

.method public static encodeHex([B)[C
    .registers 8
    .param p0, "data"    # [B

    .prologue
    .line 72
    array-length v3, p0

    .line 74
    .local v3, "l":I
    shl-int/lit8 v5, v3, 0x1

    new-array v4, v5, [C

    .line 76
    .local v4, "out":[C
    const/4 v0, 0x0

    .line 77
    .local v0, "i":I
    const/4 v1, 0x0

    .local v1, "j":I
    move v2, v1

    .end local v1    # "j":I
    .local v2, "j":I
    :goto_8
    if-lt v0, v3, :cond_b

    .line 82
    return-object v4

    .line 78
    :cond_b
    add-int/lit8 v1, v2, 0x1

    .end local v2    # "j":I
    .restart local v1    # "j":I
    sget-object v5, Lm/framework/utils/HEX;->DIGITS:[C

    aget-byte v6, p0, v0

    and-int/lit16 v6, v6, 0xf0

    ushr-int/lit8 v6, v6, 0x4

    aget-char v5, v5, v6

    aput-char v5, v4, v2

    .line 79
    add-int/lit8 v2, v1, 0x1

    .end local v1    # "j":I
    .restart local v2    # "j":I
    sget-object v5, Lm/framework/utils/HEX;->DIGITS:[C

    aget-byte v6, p0, v0

    and-int/lit8 v6, v6, 0xf

    aget-char v5, v5, v6

    aput-char v5, v4, v1

    .line 77
    add-int/lit8 v0, v0, 0x1

    goto :goto_8
.end method

.method public static encodeHexString([B)Ljava/lang/String;
    .registers 3
    .param p0, "data"    # [B

    .prologue
    .line 34
    invoke-static {p0}, Lm/framework/utils/HEX;->encodeHex([B)[C

    move-result-object v0

    .line 35
    .local v0, "charArray":[C
    new-instance v1, Ljava/lang/String;

    invoke-direct {v1, v0}, Ljava/lang/String;-><init>([C)V

    return-object v1
.end method

.method public static toByte(Ljava/lang/String;)[B
    .registers 7
    .param p0, "hexData"    # Ljava/lang/String;

    .prologue
    const/4 v3, 0x0

    .line 15
    if-nez p0, :cond_4

    .line 30
    :cond_3
    return-object v3

    .line 19
    :cond_4
    invoke-virtual {p0}, Ljava/lang/String;->length()I

    move-result v2

    .line 20
    .local v2, "len":I
    rem-int/lit8 v4, v2, 0x2

    const/4 v5, 0x1

    if-eq v4, v5, :cond_3

    .line 24
    div-int/lit8 v0, v2, 0x2

    .line 25
    .local v0, "dataLength":I
    new-array v3, v0, [B

    .line 26
    .local v3, "result":[B
    const/4 v1, 0x0

    .local v1, "i":I
    :goto_12
    if-ge v1, v0, :cond_3

    .line 28
    mul-int/lit8 v4, v1, 0x2

    mul-int/lit8 v5, v1, 0x2

    add-int/lit8 v5, v5, 0x2

    invoke-virtual {p0, v4, v5}, Ljava/lang/String;->substring(II)Ljava/lang/String;

    move-result-object v4

    const/16 v5, 0x10

    invoke-static {v4, v5}, Ljava/lang/Integer;->parseInt(Ljava/lang/String;I)I

    move-result v4

    int-to-byte v4, v4

    aput-byte v4, v3, v1

    .line 26
    add-int/lit8 v1, v1, 0x1

    goto :goto_12
.end method

.method protected static toDigit(CI)I
    .registers 6
    .param p0, "ch"    # C
    .param p1, "index"    # I

    .prologue
    .line 64
    const/16 v1, 0x10

    invoke-static {p0, v1}, Ljava/lang/Character;->digit(CI)I

    move-result v0

    .line 65
    .local v0, "digit":I
    const/4 v1, -0x1

    if-ne v0, v1, :cond_28

    .line 66
    new-instance v1, Ljava/lang/RuntimeException;

    new-instance v2, Ljava/lang/StringBuilder;

    const-string v3, "Illegal hexadecimal charcter "

    invoke-direct {v2, v3}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    invoke-virtual {v2, p0}, Ljava/lang/StringBuilder;->append(C)Ljava/lang/StringBuilder;

    move-result-object v2

    const-string v3, " at index "

    invoke-virtual {v2, v3}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v2

    invoke-virtual {v2, p1}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;

    move-result-object v2

    invoke-virtual {v2}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v2

    invoke-direct {v1, v2}, Ljava/lang/RuntimeException;-><init>(Ljava/lang/String;)V

    throw v1

    .line 68
    :cond_28
    return v0
.end method

.method public static toHex([B)Ljava/lang/String;
    .registers 7
    .param p0, "data"    # [B

    .prologue
    .line 7
    new-instance v0, Ljava/lang/StringBuffer;

    invoke-direct {v0}, Ljava/lang/StringBuffer;-><init>()V

    .line 8
    .local v0, "buffer":Ljava/lang/StringBuffer;
    const/4 v1, 0x0

    .local v1, "i":I
    :goto_6
    array-length v2, p0

    if-lt v1, v2, :cond_e

    .line 11
    invoke-virtual {v0}, Ljava/lang/StringBuffer;->toString()Ljava/lang/String;

    move-result-object v2

    return-object v2

    .line 9
    :cond_e
    const-string v2, "%02x"

    const/4 v3, 0x1

    new-array v3, v3, [Ljava/lang/Object;

    const/4 v4, 0x0

    aget-byte v5, p0, v1

    invoke-static {v5}, Ljava/lang/Byte;->valueOf(B)Ljava/lang/Byte;

    move-result-object v5

    aput-object v5, v3, v4

    invoke-static {v2, v3}, Ljava/lang/String;->format(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    move-result-object v2

    invoke-virtual {v0, v2}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    .line 8
    add-int/lit8 v1, v1, 0x1

    goto :goto_6
.end method


# virtual methods
.method public decode(Ljava/lang/Object;)[B
    .registers 6
    .param p1, "object"    # Ljava/lang/Object;

    .prologue
    .line 91
    :try_start_0
    instance-of v2, p1, Ljava/lang/String;

    if-eqz v2, :cond_f

    check-cast p1, Ljava/lang/String;

    .end local p1    # "object":Ljava/lang/Object;
    invoke-virtual {p1}, Ljava/lang/String;->toCharArray()[C

    move-result-object v0

    .line 92
    .local v0, "charArray":[C
    :goto_a
    invoke-static {v0}, Lm/framework/utils/HEX;->decodeHex([C)[B

    move-result-object v2

    return-object v2

    .line 91
    .end local v0    # "charArray":[C
    .restart local p1    # "object":Ljava/lang/Object;
    :cond_f
    check-cast p1, [C
    :try_end_11
    .catch Ljava/lang/ClassCastException; {:try_start_0 .. :try_end_11} :catch_13

    move-object v0, p1

    goto :goto_a

    .line 93
    .end local p1    # "object":Ljava/lang/Object;
    :catch_13
    move-exception v1

    .line 95
    .local v1, "e":Ljava/lang/ClassCastException;
    new-instance v2, Ljava/lang/RuntimeException;

    invoke-virtual {v1}, Ljava/lang/ClassCastException;->getMessage()Ljava/lang/String;

    move-result-object v3

    invoke-direct {v2, v3}, Ljava/lang/RuntimeException;-><init>(Ljava/lang/String;)V

    throw v2
.end method

.method public decode([B)[B
    .registers 3
    .param p1, "array"    # [B

    .prologue
    .line 86
    new-instance v0, Ljava/lang/String;

    invoke-direct {v0, p1}, Ljava/lang/String;-><init>([B)V

    invoke-virtual {v0}, Ljava/lang/String;->toCharArray()[C

    move-result-object v0

    invoke-static {v0}, Lm/framework/utils/HEX;->decodeHex([C)[B

    move-result-object v0

    return-object v0
.end method

.method public encode([B)[B
    .registers 4
    .param p1, "array"    # [B

    .prologue
    .line 100
    new-instance v0, Ljava/lang/String;

    invoke-static {p1}, Lm/framework/utils/HEX;->encodeHex([B)[C

    move-result-object v1

    invoke-direct {v0, v1}, Ljava/lang/String;-><init>([C)V

    invoke-virtual {v0}, Ljava/lang/String;->getBytes()[B

    move-result-object v0

    return-object v0
.end method

.method public encode(Ljava/lang/Object;)[C
    .registers 6
    .param p1, "object"    # Ljava/lang/Object;

    .prologue
    .line 105
    :try_start_0
    instance-of v2, p1, Ljava/lang/String;

    if-eqz v2, :cond_f

    check-cast p1, Ljava/lang/String;

    .end local p1    # "object":Ljava/lang/Object;
    invoke-virtual {p1}, Ljava/lang/String;->getBytes()[B

    move-result-object v0

    .line 106
    .local v0, "byteArray":[B
    :goto_a
    invoke-static {v0}, Lm/framework/utils/HEX;->encodeHex([B)[C

    move-result-object v2

    return-object v2

    .line 105
    .end local v0    # "byteArray":[B
    .restart local p1    # "object":Ljava/lang/Object;
    :cond_f
    check-cast p1, [B
    :try_end_11
    .catch Ljava/lang/ClassCastException; {:try_start_0 .. :try_end_11} :catch_13

    move-object v0, p1

    goto :goto_a

    .line 107
    .end local p1    # "object":Ljava/lang/Object;
    :catch_13
    move-exception v1

    .line 109
    .local v1, "e":Ljava/lang/ClassCastException;
    new-instance v2, Ljava/lang/RuntimeException;

    invoke-virtual {v1}, Ljava/lang/ClassCastException;->getMessage()Ljava/lang/String;

    move-result-object v3

    invoke-direct {v2, v3}, Ljava/lang/RuntimeException;-><init>(Ljava/lang/String;)V

    throw v2
.end method
